package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.sys.modular.system.model.params.BtyMdCaiwuParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyMdFuzhumxzParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyMdFuzhumxzResult;
import cn.stylefeng.guns.sys.modular.system.model.result.OrderDataResult;
import cn.stylefeng.guns.sys.modular.system.model.result.OrderDataResults;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdFuzhumxzService;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdLirunbiaoService;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdZichanfzbService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


/**
 * 门店财务主表控制器
 *
 * @author jiangge
 * @Date 2021-09-08 10:50:59
 */
@Controller
@RequestMapping("/btyMdCaiwuApi2")
public class BtyMdCaiwuApi2Controller extends BaseController {
    private Logger logger = LoggerFactory.getLogger(BtyMdCaiwuApi2Controller.class);

    @Autowired
    private BtyMdZichanfzbService btyMdZichanfzbService;
    @Autowired
    private BtyMdLirunbiaoService btyMdLirunbiaoService;
    @Autowired
    private BtyMdFuzhumxzService btyMdFuzhumxzService;

    /**
     * app查询-资产负债表
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllZcfzbData", method = RequestMethod.POST)
    public ResponseData findAllZcfzbData(BtyMdCaiwuParam param) {
        logger.info("app查询-资产负债表参数：{}", param.toString());
        if (StringUtils.isBlank(param.getYaoma())) {
            return ResponseData.error(412, "请求失败，妖码不能为空");
        }
        if (StringUtils.isBlank(param.getKjqj())) {
            return ResponseData.error(412, "请求失败，会计月不能为空");
        }

        List<OrderDataResult> detail = this.btyMdZichanfzbService.findAllZcfzbData(param);
        return ResponseData.success(detail);
    }

    /**
     * app查询-资产负债表
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/newfindAllZcfzbData", method = RequestMethod.POST)
    public ResponseData newfindAllZcfzbData(BtyMdCaiwuParam param) {
        logger.info("app查询-资产负债表参数：{}", param.toString());
        if (StringUtils.isBlank(param.getYaoma())) {
            return ResponseData.error(412, "请求失败，妖码不能为空");
        }
        if (StringUtils.isBlank(param.getKjqj())) {
            return ResponseData.error(412, "请求失败，会计月不能为空");
        }
        List<OrderDataResults> alldetail=new ArrayList<>();
        List<OrderDataResult> detail = this.btyMdZichanfzbService.findAllZcfzbData(param);
        List<OrderDataResult> sydetail = this.btyMdZichanfzbService.syfindAllZcfzbData(param);
        List<OrderDataResult> sndetail = this.btyMdZichanfzbService.snfindAllZcfzbData(param);
        OrderDataResults osrderDataResults=new OrderDataResults();
        osrderDataResults.setListkjqj(detail);
        osrderDataResults.setListsy(sydetail);
        osrderDataResults.setListsn(sndetail);
        alldetail.add(osrderDataResults);
        return ResponseData.success(alldetail);
    }

    /**
     * app查询-损益表(即利润表)
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllLirunData", method = RequestMethod.POST)
    public ResponseData findAllLirunData(BtyMdCaiwuParam param) {
        logger.info("app查询-利润表参数：{}", param.toString());
        if (StringUtils.isBlank(param.getYaoma())) {
            return ResponseData.error(412, "请求失败，妖码不能为空");
        }
        if (StringUtils.isBlank(param.getKjqj())) {
            return ResponseData.error(412, "请求失败，会计月不能为空");
        }

        List<OrderDataResult> detail = this.btyMdLirunbiaoService.findAllLirunData(param);
        return ResponseData.success(detail);
    }

    /**
     * app查询-损益表(即利润表)
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/newfindAllLirunData", method = RequestMethod.POST)
    public ResponseData newfindAllLirunData(BtyMdCaiwuParam param) {
        logger.info("app查询-利润表参数：{}", param.toString());
        if (StringUtils.isBlank(param.getYaoma())) {
            return ResponseData.error(412, "请求失败，妖码不能为空");
        }
        if (StringUtils.isBlank(param.getKjqj())) {
            return ResponseData.error(412, "请求失败，会计月不能为空");
        }

        List<OrderDataResults> alldetail=new ArrayList<>();
        List<OrderDataResult> detail = this.btyMdLirunbiaoService.findAllLirunData(param);
        List<OrderDataResult> sydetail = this.btyMdLirunbiaoService.syfindAllLirunData(param);
        List<OrderDataResult> sndetail = this.btyMdLirunbiaoService.snfindAllLirunData(param);
        OrderDataResults osrderDataResults=new OrderDataResults();
        osrderDataResults.setListkjqj(detail);
        osrderDataResults.setListsy(sydetail);
        osrderDataResults.setListsn(sndetail);
        alldetail.add(osrderDataResults);
        return ResponseData.success(alldetail);
    }

    /**
     * app查询-费用明细
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping(value = "/findAllFzmxzData", method = RequestMethod.POST)
    public ResponseData findAllFzmxzData(BtyMdFuzhumxzParam param) {
        logger.info("app查询-辅助明细账参数：{}", param.toString());
        if (StringUtils.isBlank(param.getYaoma())) {
            return ResponseData.error(412, "请求失败，妖码参数不能为空");
        }
        if (StringUtils.isBlank(param.getDate())) {
            return ResponseData.error(412, "请求失败，日期参数不能为空");
        }
        if (StringUtils.isBlank(param.getOrderBy())) {
            return ResponseData.error(412, "请求失败，排序参数orderBy不能为空");
        }
        if (StringUtils.isBlank(param.getSc())) {
            return ResponseData.error(412, "请求失败，排序参数sc不能为空");
        }
        param.setKjYear(Integer.valueOf(param.getDate().substring(0, 4)));
        param.setKjMonth(Integer.valueOf(param.getDate().substring(5, 7)));
        List<BtyMdFuzhumxzResult> detail = this.btyMdFuzhumxzService.findAllFzmxzData(param);
        return ResponseData.success(detail);
    }

}


